//
//  BookOrderView.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/6.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "BookOrderView.h"
@interface BookOrderView()<CAAnimationDelegate>
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UIButton *seeAllBtn;
@property (nonatomic,strong) NSArray *itemsArray;

@property (nonatomic,strong) UIView *contentFollwsView;
@property (nonatomic,strong) UIView *wufollowsView;
@property (nonatomic,strong) UILabel *wuNameLabel;
@property (nonatomic,strong) UILabel *dateLabel;
@property (nonatomic,strong) UIImageView *headerImgView;
@property (nonatomic,strong) UILabel *statuslabel;
@property (nonatomic,strong) UILabel *descrpLabel;

@property (nonatomic,strong) UIView *wufollowsView2;
@property (nonatomic,strong) UILabel *wuNameLabel2;
@property (nonatomic,strong) UILabel *dateLabel2;
@property (nonatomic,strong) UIImageView *headerImgView2;
@property (nonatomic,strong) UILabel *statuslabel2;
@property (nonatomic,strong) UILabel *descrpLabel2;


@end

@implementation BookOrderView


- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, TSScaleW(353), TSScaleW(224));
        self.backgroundColor = kWhiteColor;
        self.cornerRadius = TSScaleW(5);
        [self addSubview:self.titleLabel];
        [self addSubview:self.seeAllBtn];
        self.itemsArray = @[@"待付款",@"待发货",@"待收货",@"待评价",@"退款/售后"];
        [self addSubview:self.contentFollwsView];
        [self groupAnimation];
    }
    return self;
}
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [TSWLTools allocLabel:@"我的订单" font:systemBoldFont(TSScaleW(13)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(12), TSScaleW(17), TSScaleW(100), TSScaleW(13)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _titleLabel;
}
-(UIButton *)seeAllBtn{
    if (!_seeAllBtn) {
        _seeAllBtn = [TSWLTools allocButtonTitle:@"查看全部>" font:systemFont(TSScaleW(11)) textColor:kGrayTxtColor image:nil frame:CGRectMake(self.width - TSScaleW(88), TSScaleW(10), TSScaleW(88), TSScaleW(30)) sel:@selector(seeAllBtnAction:) taget:self];
    }
    return _seeAllBtn;
}
-(void)seeAllBtnAction:(UIButton *)sender
{
    !self.seeAllOrderBlock?:self.seeAllOrderBlock();
}
-(void)setItemsArray:(NSArray *)itemsArray{
    _itemsArray = itemsArray;
    NSArray *array = @[@"daifukuan",@"待发货拷贝_d",@"待收货拷贝_d",@"待评价_d",@"icon_退款售后"];
   
    CGFloat w = self.width/_itemsArray.count;
    for (int i = 0; i < _itemsArray.count; i ++) {
        UIButton *btn = [TSWLTools allocButtonTitle:_itemsArray[i] font:systemFont(TSScaleW(12)) textColor:kMainTxtColor image:[UIImage imageNamed:array[i]] frame:CGRectMake(i *w, TSScaleW(14)+ _titleLabel.bottom, w, TSScaleW(70)) sel:@selector(btnAction:) taget:self];
       // CGFloat f = [self returnWidth:_itemsArray[i] font:TSScaleW(12)];
        [btn setBtnDownLabelUpDownOffSet:0 leftOffset:0];
        [self addSubview:btn];
    }
}
-(void)btnAction:(UIButton *)sender{
    !self.orderSelectBlock?:self.orderSelectBlock(sender.titleLabel.text);
}
-(UIView *)wufollowsView{
    if (!_wufollowsView) {
        _wufollowsView = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(12), 0, TSScaleW(329), TSScaleW(80))];
        _wufollowsView.backgroundColor = kSubBacColor;
        _wufollowsView.cornerRadius = TSScaleW(5);
        [_wufollowsView addSubview:self.wuNameLabel];
        [_wufollowsView addSubview:self.dateLabel];
        [_wufollowsView addSubview:self.headerImgView];
        [_wufollowsView addSubview:self.statuslabel];
        [_wufollowsView addSubview:self.descrpLabel];
    }
    return _wufollowsView;
}

-(UILabel *)wuNameLabel{
    if (!_wuNameLabel) {
        _wuNameLabel = [TSWLTools allocLabel:@"最新物流1" font:systemFont(TSScaleW(11)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(22), TSScaleW(12), _wufollowsView.width - TSScaleW(42), TSScaleW(11)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _wuNameLabel;
}
-(UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [TSWLTools allocLabel:@"01-02" font:systemFont(TSScaleW(11)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(22), TSScaleW(12), _wufollowsView.width - TSScaleW(42), TSScaleW(11)) textAlignment:(NSTextAlignmentRight)];
    }
    return _dateLabel;
}
-(UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(_wuNameLabel.left, _wuNameLabel.bottom + TSScaleW(9), TSScaleW(33), TSScaleW(33))];
        _headerImgView.backgroundColor = kGrayTxtColor;
    }
    return _headerImgView;
}

-(UILabel *)statuslabel{
    if (!_statuslabel) {
        _statuslabel = [TSWLTools allocLabel:@"运输中" font:systemFont(TSScaleW(13)) textColor:kBlueColor frame:CGRectMake(TSScaleW(17) + _headerImgView.right, TSScaleW(33), TSScaleW(235), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _statuslabel;
}
-(UILabel *)descrpLabel{
    if (!_descrpLabel) {
        _descrpLabel = [TSWLTools allocLabel:@"【开封市】开封派件员：君临天下驿站的 电…" font:systemFont(TSScaleW(13)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(17) + _headerImgView.right, TSScaleW(10) + _statuslabel.bottom, TSScaleW(235), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _descrpLabel;
}

-(UIView *)wufollowsView2{
    if (!_wufollowsView2) {
        _wufollowsView2 = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(24) + _wufollowsView.right, 0, TSScaleW(329), TSScaleW(80))];
        _wufollowsView2.backgroundColor = kSubBacColor;
        _wufollowsView2.cornerRadius = TSScaleW(5);
        [_wufollowsView2 addSubview:self.wuNameLabel2];
        [_wufollowsView2 addSubview:self.dateLabel2];
        [_wufollowsView2 addSubview:self.headerImgView2];
        [_wufollowsView2 addSubview:self.statuslabel2];
        [_wufollowsView2 addSubview:self.descrpLabel2];
    }
    return _wufollowsView2;
}

-(UILabel *)wuNameLabel2{
    if (!_wuNameLabel2) {
        _wuNameLabel2 = [TSWLTools allocLabel:@"最新物流2" font:systemFont(TSScaleW(11)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(22), TSScaleW(12), _wufollowsView2.width - TSScaleW(42), TSScaleW(11)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _wuNameLabel2;
}
-(UILabel *)dateLabel2{
    if (!_dateLabel2) {
        _dateLabel2 = [TSWLTools allocLabel:@"01-02" font:systemFont(TSScaleW(11)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(22), TSScaleW(12), _wufollowsView2.width - TSScaleW(42), TSScaleW(11)) textAlignment:(NSTextAlignmentRight)];
    }
    return _dateLabel2;
}
-(UIImageView *)headerImgView2{
    if (!_headerImgView2) {
        _headerImgView2 = [[UIImageView alloc]initWithFrame:CGRectMake(_wuNameLabel2.left, _wuNameLabel2.bottom + TSScaleW(9), TSScaleW(33), TSScaleW(33))];
        _headerImgView2.backgroundColor = kGrayTxtColor;
    }
    return _headerImgView2;
}

-(UILabel *)statuslabel2{
    if (!_statuslabel2) {
        _statuslabel2 = [TSWLTools allocLabel:@"运输中" font:systemFont(TSScaleW(13)) textColor:kBlueColor frame:CGRectMake(TSScaleW(17) + _headerImgView2.right, TSScaleW(33), TSScaleW(235), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _statuslabel2;
}
-(UILabel *)descrpLabel2{
    if (!_descrpLabel2) {
        _descrpLabel2 = [TSWLTools allocLabel:@"【开封市】开封派件员：君临天下驿站的 电…" font:systemFont(TSScaleW(13)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(17) + _headerImgView2.right, TSScaleW(10) + _statuslabel2.bottom, TSScaleW(235), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _descrpLabel2;
}
-(UIView *)contentFollwsView{
    if (!_contentFollwsView) {
        _contentFollwsView = [[UIView alloc]initWithFrame:CGRectMake(-self.width, TSScaleW(88) + _titleLabel.bottom, self.width *2, TSScaleW(80))];
        [_contentFollwsView addSubview:self.wufollowsView];
        [_contentFollwsView addSubview:self.wufollowsView2];
    }
    return _contentFollwsView;
}
#pragma mark ---动画



-(void)groupAnimation{
//    //位移动画
    [self addSubview:self.contentFollwsView];
   
    CAKeyframeAnimation *anima1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    NSValue *value0 = [NSValue valueWithCGPoint:CGPointMake(self.wufollowsView.centerX, self.contentFollwsView.centerY)];
    NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(self.wufollowsView2.centerX, self.contentFollwsView.centerY)];
   
    anima1.values = [NSArray arrayWithObjects:value0,value1, nil];
    anima1.duration = .5f;
//
//    //缩放动画
//    CABasicAnimation *anima2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//    anima2.fromValue = [NSNumber numberWithFloat:0.5f];
//    anima2.toValue = [NSNumber numberWithFloat:1.0f];
//    anima2.duration = 1.f;
    
//    //旋转动画
//    CABasicAnimation *anima3 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//    anima3.toValue = [NSNumber numberWithFloat:M_PI*4];
//
    //组动画
    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
   // groupAnimation.animations = [NSArray arrayWithObjects:anima1,anima2,anima3, nil];
    groupAnimation.animations = [NSArray arrayWithObjects:anima1, nil];
    groupAnimation.duration = 5.0f;
    groupAnimation.delegate = self;
    groupAnimation.repeatCount = NSIntegerMax;
    //groupAnimation.autoreverses = YES;
    [_contentFollwsView.layer addAnimation:groupAnimation forKey:@"groupAnimation"];
    
  
    
}

- (void)animationDidStart:(CAAnimation *)anim
{
   // self.userInteractionEnabled = NO;
};



- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    if (flag) {
        _contentFollwsView.left = self.width;
    }
};
-(void)setWulliuArray:(NSArray *)wulliuArray{
    _wulliuArray = wulliuArray;
    
    if (_wulliuArray.count == 0) {
        self.height = _contentFollwsView.top;
        _contentFollwsView.hidden = YES;
        !self.reloadFrameBlock?:self.reloadFrameBlock();
    }
}
@end
